package com.matrix.java.chap_06;

import java.util.Scanner;

/*
    求一个整数各位数字之和
 */
public class Ex6_02 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.print("整数: ");
        long num = input.nextLong();
        input.close();
        System.out.println(sumDigits(num));
    }

    private static int sumDigits(long num) {
        int sum = 0;
        do {
            sum += num % 10;
            num /= 10;
        } while (num != 0);
        return sum;
    }
}
